<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>视频监控系统</title>
    <style type="text/css">
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
    
        html, body {
            height: 100%;
            font-family: 'Microsoft YaHei', sans-serif;
        }
    
        body {
            background: url('333.png') center/cover no-repeat fixed;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }
    
        .control-panel {
            width: 90%;
            max-width: 800px;
            background: rgba(255, 255, 255, 0.2);
            border-radius: 12px;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.3);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
            padding: 20px;
            display: flex;
            flex-direction: column;
            gap: 15px;
        }
    
        .video-stream {
            width: 100%;
            background: rgba(0, 0, 0, 0.2);
            border-radius: 8px;
            aspect-ratio: 16/9;
            object-fit: cover;
            border: 1px solid rgba(255, 255, 255, 0.2);
        }
    
        .control-btn {
            padding: 8px 20px;
            background: rgba(50, 50, 50, 0.8);
            color: white;
            border: none;
            border-radius: 20px;
            cursor: pointer;
            transition: all 0.3s;
            font-size: 14px;
            min-width: 120px;
            align-self: center;
            text-decoration: none; /* 新增：去除下划线 */
            display: flex; /* 新增：启用flex布局 */
            justify-content: center; /* 新增：水平居中 */
            align-items: center; /* 新增：垂直居中 */
        }
    
        .control-btn:hover {
            background: rgba(74, 140, 247, 0.8);
            transform: translateY(-2px);
        }
    
        .nav-footer-wrapper {
            display: flex;
            flex-direction: column;
            gap: 15px;
            margin-top: 10px;
        }
    
        .nav-links {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-top: 20px;
            font-size: 14px;
            color: #666;
        }
            
        .nav-links a {
            color: #666;
            text-decoration: none;
            transition: color 0.3s;
        }
            
        .nav-links a:hover {
            color: #333;
        }
            
        .footer {
            text-align: center;
            font-size: 12px;
            color: rgba(255, 255, 255, 0.8);
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
        }
    
        .snapshot-preview {
            position: absolute;
            bottom: 20px;
            right: 20px;
            width: 120px;
            border: 2px solid white;
            border-radius: 4px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.3);
            display: none;
        }
    
        @media (max-width: 600px) {
            .control-panel {
                width: 100%;
                padding: 15px;
            }
            
            .control-btn {
                padding: 6px 12px;
                min-width: 100px;
                font-size: 12px;
            }
            
            .snapshot-preview {
                width: 80px;
                bottom: 10px;
                right: 10px;
            }
        }
    </style>
</head>
<body>
    <div class="control-panel">
        <img class="video-stream" src="./?action=stream" alt="视频流" id="videoStream"/>
        <img class="snapshot-preview" id="snapshotPreview" alt="截图预览"/>
        
        <button class="control-btn" id="captureBtn">截图保存</button>
        <a class="control-btn" id="downloadBtn" style="display:none;">下载截图</a>
        
        <div class="nav-footer-wrapper">
            <div class="nav-links">
                <a href="http://192.168.43.241/mainpage.html">主页</a>
                <a href="http://192.168.43.241/stm32.html">STM32示例</a>
                <a href="http://192.168.43.241/modbusslave.html">Modbus示例</a>
                <a href="http://192.168.43.241:8080/stream_simple.html">视频监控</a>
            </div>
            <div class="footer">
                MJPG-Streamer 视频流服务 | 技术支持电话: 400-706-1880
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const videoStream = document.getElementById('videoStream');
            const captureBtn = document.getElementById('captureBtn');
            const downloadBtn = document.getElementById('downloadBtn');
            const snapshotPreview = document.getElementById('snapshotPreview');
            
            let currentSnapshot = null;
            
            const canvas = document.createElement('canvas');
            const ctx = canvas.getContext('2d');
            
            captureBtn.addEventListener('click', function() {
                canvas.width = videoStream.videoWidth || videoStream.width;
                canvas.height = videoStream.videoHeight || videoStream.height;
                
                ctx.drawImage(videoStream, 0, 0, canvas.width, canvas.height);
                
                const imageData = canvas.toDataURL('image/jpeg', 0.9);
                currentSnapshot = imageData;
                
                snapshotPreview.src = imageData;
                snapshotPreview.style.display = 'block';
                
                downloadBtn.style.display = 'flex'; /* 修改为flex以保持居中 */
                downloadBtn.href = imageData;
                downloadBtn.download = 'snapshot_' + new Date().toISOString().replace(/[:.]/g, '-') + '.jpg';
                
                setTimeout(() => {
                    snapshotPreview.style.opacity = '0.5';
                }, 3000);
            });
            
            snapshotPreview.addEventListener('mouseenter', function() {
                this.style.opacity = '1';
            });
            
            snapshotPreview.addEventListener('mouseleave', function() {
                this.style.opacity = '0.5';
            });
            
            snapshotPreview.addEventListener('click', function() {
                if (currentSnapshot) {
                    const win = window.open('', '_blank');
                    win.document.write(`<img src="${currentSnapshot}" style="max-width:100%;"/>`);
                }
            });
        });
    </script>
</body>
</html>